﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;

namespace CC98.Xaml.Converters
{
    public class BoolToStringConverter : DependencyObject, IValueConverter
    {
        public string TrueString
        {
            get { return (string)GetValue(TrueStringProperty); }
            set { SetValue(TrueStringProperty, value); }
        }

        public static readonly DependencyProperty TrueStringProperty =
            DependencyProperty.Register("TrueString", typeof(string), typeof(BoolToStringConverter), new PropertyMetadata(null));

        public string FalseString
        {
            get { return (string)GetValue(FalseStringProperty); }
            set { SetValue(FalseStringProperty, value); }
        }

        public static readonly DependencyProperty FalseStringProperty =
            DependencyProperty.Register("FalseString", typeof(string), typeof(BoolToStringConverter), new PropertyMetadata(null));


        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value is bool)
            {
                bool v = (bool)value;
                if (v)
                    return this.TrueString;
                else
                    return this.FalseString;
            }
            else
            {
                if (value != null)
                    throw new ArgumentException("Invalid value type:" + value.GetType() + ", expected bool");
                else
                    throw new ArgumentNullException("value");
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }
}
